package com.clearance.mine_clearance.controller;

import com.alibaba.fastjson.JSON;
import com.clearance.mine_clearance.config.Constants;
import com.clearance.mine_clearance.entry.Config;
import com.clearance.mine_clearance.entry.Result;
import com.clearance.mine_clearance.mapper.ConfigMapper;
import com.clearance.mine_clearance.untils.RedisUntils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin("*")
@RestController
@RequestMapping("/mine/config")
public class ConfigController {
    @Autowired
    private ConfigMapper configMapper;

    @GetMapping("/getConfig")
    public Result<Config> getConfig(){
        Config config = configMapper.selectById(1);
        return new Result<Config>().success(config);
    }
    @PostMapping("/updateConfig")
    public Result<Config> updateConfig(@RequestBody Config config){
        configMapper.updateById(config);
        RedisUntils.setValue(Constants.config, JSON.toJSONString(config));
        return new Result<Config>().success(config);
    }
}


















